package com.axun.fileexplore

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Toast
import com.axun.explorelib.activity.ChooseFileActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        btn_open.setOnClickListener {
            checkPermission()
        }
    }

    private fun checkPermission(){
        if (PermissionRequest.lacksPermissions(this,PermissionRequest.permissions)){
            PermissionRequest.requestAll(this,object : PermissionRequest.OnPermissionCallback {
                override fun onPermissionSuccess() {
                    toNext()
                }

                override fun onPermissionFailed() {
                   Toast.makeText(this@MainActivity,"请申请权限",Toast.LENGTH_SHORT).show()
                }

            })
        }else{
            toNext()
        }
    }

    private fun toNext(){
        startActivity(Intent(this@MainActivity, ChooseFileActivity::class.java))
    }
}
